package com.hyl.authdemo.service;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @Description TODO
 * @Author hyl
 * @Date 2022/7/5 15:50
 **/
@Service("redisService")
public class RedisServiceImpl implements RedisService{

	@Resource
	private StringRedisTemplate stringRedisTemplate;

	@Resource
	private RedisTemplate redisTemplate;


	@Override
	public void set(String key, String value) {
		ValueOperations<String,String> tmp = stringRedisTemplate.opsForValue();
		tmp.set(key, value);
	}

	@Override
	public void set(String key, String value, long expTime) {
		ValueOperations<String,String> tmp = stringRedisTemplate.opsForValue();
		tmp.set(key, value, expTime, TimeUnit.MINUTES);
	}

	@Override
	public String get(String key) {
		return stringRedisTemplate.opsForValue().get(key);
	}

	@Override
	public void del(String key) {
		stringRedisTemplate.delete(key);
	}

	public StringRedisTemplate getStringRedisTemplate() {
		return stringRedisTemplate;
	}

	public RedisTemplate getRedisTemplate() {
		return redisTemplate;
	}
}
